package Dao.Daoimpl;

import Dao.Dao_type;
import enty.Student;
import enty.queryVo;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class Studentimpl implements Dao_type {
     private SqlSessionFactory factory=null;

    public Studentimpl(SqlSessionFactory sqlSessionFactory) {
        this.factory=sqlSessionFactory;
    }

    /**
     * 实现类里 的SqlSession 不能自己创建由外部传入
     * 每一个方法的执行对应一个单独 SqlSession
     *
     * **/
    @Override
    public Student selectone(int studentno) {
      SqlSession sqlSession= factory.openSession();
      sqlSession.commit();
      Student student= sqlSession.selectOne("selectone",studentno);

     return student;


    }

    @Override
    public List<Student> SelectByname(String name) {
        SqlSession sqlSession= factory.openSession();
        List<Student> list=sqlSession.selectList("SelectByname",name);
        sqlSession.close();
       return list;

    }

    @Override
    public int Delete(int num) {
        SqlSession sqlSession= factory.openSession();
        int i=sqlSession.delete("Delete",num);

        sqlSession.commit();
        sqlSession.close();
        return    i;

    }

    @Override
    public int Update(Student student) {
        SqlSession sqlSession= factory.openSession();
        int i=sqlSession.update("Update",student);

        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public int Insert(Student student) {
        SqlSession sqlSession= factory.openSession();
        int i=sqlSession.insert("Insert",student);

        sqlSession.commit();
        sqlSession.close();
        return i;
    }

    @Override
    public List<Student> SelectByname1(queryVo queryVo) {
        SqlSession sqlSession= factory.openSession();
       List<Student> list= sqlSession.selectList("queryVo",queryVo);
       sqlSession.close();
        return list;
    }


}
